<template>
  <div >
    <div class="page-content-forms">
      <a-col :span="23">
        <a-space>
          <div>
            <label>任务ID:</label>
            <a-input placeholder="like 53fc156d_8011_455c_9c9a_627068f4" style="width: 250px"   @change="change_taskid" v-model="taskid" allowClear/>
          </div>
          <div>
              <label>ai id:</label>
              <a-input placeholder="like 53fc156d_8011_455c_9c9a_627068f4" style="width: 250px"   @change="change_aiid" v-model="aiid" allowClear/>
          </div>
          <div v-show="isaggregate==false">
              <label>软件:  </label>
              <a-select  v-model="ai_soft" style="width: 80px" allowClear @change="ai_soft_change">
                <a-select-option value="alibaba" >alibaba</a-select-option>
                <a-select-option value="baidu" >baidu</a-select-option>
              </a-select>
          </div>
          <div v-show="isaggregate==false">
              <label>AI状态:</label>
              <a-select  v-model="ai_status" style="width: 80px" allowClear @change="ai_status_change">
                <a-select-option value="0" >等待</a-select-option>
                <a-select-option value="1" >成功</a-select-option>
                <a-select-option value="2" >失败</a-select-option>
                <a-select-option value="3" >运行</a-select-option>
              </a-select>
          </div>
          <div v-show="isaggregate==false">
              <label>裁切:</label>
              <a-select  v-model="clip_type" style="width: 80px" allowClear @change="clip_type_change">
                <a-select-option value="1" >是</a-select-option>
                <a-select-option value="0" >否</a-select-option>
              </a-select>
          </div>
          <div v-show="isaggregate==false">
              <label>裁切状态:</label>
              <a-select  v-model="clip_status" style="width: 80px" allowClear @change="clip_status_change">
                <a-select-option value="waiting" >等待</a-select-option>
                <a-select-option value="success" >成功</a-select-option>
                <a-select-option value="error" >失败</a-select-option>
                <a-select-option value="running" >运行</a-select-option>
                <a-select-option value="igore" >无需裁切</a-select-option>
              </a-select>
          </div>
          <div v-show="isaggregate==false">
              <label>转入:</label>
              <a-select  v-model="totask_type" style="width: 80px" allowClear @change="totask_type_change">
                <a-select-option value="1" >是</a-select-option>
                <a-select-option value="0" >否</a-select-option>
              </a-select>
          </div>
          <div v-show="isaggregate==false">
              <label>转入状态:</label>
              <a-select  v-model="totask_status" style="width: 80px" allowClear @change="totask_status_change">
                <a-select-option value="waiting" >等待</a-select-option>
                <a-select-option value="success" >成功</a-select-option>
                <a-select-option value="error" >失败</a-select-option>
                <a-select-option value="running" >运行</a-select-option>
              </a-select>
          </div>

          <div v-show="isaggregate==false">
              <label>回调:</label>
              <a-select  v-model="action_type" style="width: 70px" allowClear @change="action_type_change">
                <a-select-option value="1" >是</a-select-option>
                <a-select-option value="0" >否</a-select-option>
              </a-select>
          </div>
          <div v-show="isaggregate==false">
              <label>回调状态:</label>
              <a-select  v-model="action_status" style="width: 70px" allowClear @change="action_status_change">
                <a-select-option value="success" >成功</a-select-option>
                <a-select-option value="fail" >失败</a-select-option>
              </a-select>
          </div>


          
        </a-space>
      </a-col>
      <a-col :span="1">
        <div >
          <a-button type="primary" @click="click_and_search">查询</a-button>
      </div>
      </a-col>
    </div>
    <div class="page-content-table">
      <a-table 
      :columns="aggregate_table_columns" 
      :data-source="aggregate_table_data" 
      bordered 
      :pagination="aggregate_table_pagination"  
      size="small"
      @change="ai_table_change_pagination"
      :customRow="aggregate_table_row_event"
      style="user-select: text;"
      v-show="isaggregate==true"
      >
        <template #expandedRowRender="{ record }">
          <a-layout-content style="margin: 10px;">
            <a-descriptions title="其他信息" bordered size="small"> 
              <!-- <a-descriptions-item label="使用者">{{record.user}}</a-descriptions-item>
              <a-descriptions-item label="合并ID">{{record.mergeid}}</a-descriptions-item>
              <a-descriptions-item label="AI任务ID">{{record.taskid}}</a-descriptions-item>

              <a-descriptions-item label="AI开始时间">{{GetTime(record.ai_app.start_time)}}</a-descriptions-item>
              <a-descriptions-item label="AI结束时间">{{GetTime(record.ai_app.end_time)}}</a-descriptions-item>
              <a-descriptions-item label="AI耗时">
                  <div  v-show="record.ai_app.finished=='1'"> {{record.ai_app.elapsed_time}}</div>
                  <a-progress :percent="record.process" v-show="record.ai_app.finished=='0'"/>
              </a-descriptions-item>
              <a-descriptions-item label="AI状态" :span="3">{{record.ai_app && record.ai_app.finished_msg}}</a-descriptions-item>


              <a-descriptions-item label="是否裁切">{{record.work}}</a-descriptions-item>
              <a-descriptions-item label="裁切队列开始时间">{{GetTime(record.queue_time_s)}}</a-descriptions-item>
              <a-descriptions-item label="裁切队列结束时间">{{GetTime(record.queue_time_e)}}</a-descriptions-item>
              

              <a-descriptions-item label="裁切开始时间">{{GetTime(record.clip_time_s)}}</a-descriptions-item>
              <a-descriptions-item label="裁切结束时间">{{GetTime(record.clip_time_e)}}</a-descriptions-item>
              <a-descriptions-item label="AI图斑数量">{{record.num}}</a-descriptions-item>
              <a-descriptions-item label="回调路径" :span="3">{{record.action}}</a-descriptions-item> -->
            </a-descriptions>
          </a-layout-content>
        </template>
        <template #bodyCell="{ text, record, index, column }">
          <template v-if="column.dataIndex === 'operation'">
            <span class="table-operation">
                <a-dropdown>
                  <a class="ant-dropdown-link" @click.prevent>操作<DownOutlined /></a>
                  <template #overlay>
                      <a-menu>
                          <a-menu-item>
                            <a href="javascript:;" @click="search_ai(record)">查询具体任务</a>
                          </a-menu-item>
                      </a-menu>
                  </template>
                </a-dropdown>
            </span>
          </template> 
        </template>
      </a-table>
      <a-table 
      :columns="ai_table_columns" 
      :data-source="ai_table_data" 
      bordered 
      :pagination="ai_table_pagination"  
      size="small"
      @change="ai_table_change_pagination"
      @expand="ai_table_expand"
      style="user-select: text;"
      v-show="isaggregate==false"
      >
        <template #expandedRowRender="{ record }">
          <a-layout-content style="margin: 10px;">
            <a-descriptions title="" :bordered="true" size="small" :column="2"> 
            <a-descriptions-item label="前影像"  :span="1">
               {{record.pre}}
            </a-descriptions-item>
             <a-descriptions-item label="后影像"  :span="1" >
               {{record.lst}}
            </a-descriptions-item>
            <a-descriptions-item label="AI任务"  :span="1">
              <a-space direction="vertical">
                <span>
                  阿里任务-<span>{{record.soft.alibaba?"有":"无"}}</span>
                </span>
                 <span>
                  进入队列时间:  {{GetTime(GetObjectvale(record,['soft','alibaba','ai_time_s']))}}      结束时间:{{GetTime(GetObjectvale(record,['soft','alibaba','ai_time_e']))}}
                </span>
                <span>
                   解译状态:{{GetObjectvale(record,['soft','alibaba','aistatus'])=="1"?'success':'fail'}}        解译信息:{{GetObjectvale(record,['soft','alibaba','aimessage'])}}
                </span>
              </a-space>
            </a-descriptions-item>
            <a-descriptions-item label="AI任务"  :span="1">
              <a-space direction="vertical">
                 <span>
                  百度任务-{{record.soft.baidu?"有":"无"}}
                </span>
                 <span >
                  进入队列时间:  {{GetTime(GetObjectvale(record,['soft','baidu','ai_time_s']))}}     结束时间:  {{GetTime(GetObjectvale(record,['soft','baidu','ai_time_e']))}}
                </span>
                  <span>
                   解译状态:{{GetObjectvale(record,['soft','baidu','aistatus'])=="1"?'success':'fail'}}        解译信息:{{GetObjectvale(record,['soft','baidu','aimessage'])}}
                </span>
              </a-space>
            </a-descriptions-item>
            <a-descriptions-item label="裁切任务"  :span="1">
              <a-space direction="vertical">
                <a-space>
                  <span>
                      裁切任务-<span>{{GetObjectvale(record,['clip','type'])==1?"有":"无"}}</span>
                  </span>
                </a-space>
                 <a-space>
                  <span>
                    裁切状态:  {{GetObjectvale(record,['clip','status'])}}
                  </span>
                  <span>
                    裁切信息:{{GetObjectvale(record,['clip','msg'])}}
                  </span>
                </a-space>
                <a-space>
                  <span>
                    裁切进入队列时间:{{GetTime(GetObjectvale(record,['clip','queue_time_s']))}}
                  </span>
                  <span>
                    裁切离开队列时间:{{GetTime(GetObjectvale(record,['clip','queue_time_e']))}}
                  </span>
                </a-space>
                <a-space>
                  <span>
                    裁切开始时间:{{GetTime(GetObjectvale(record,['clip','clip_time_s']))}}
                  </span>
                  <span>
                    裁切结束时间:{{GetTime(GetObjectvale(record,['clip','clip_time_e']))}}
                  </span>
                </a-space>
                <div>
                  <a-col :span="4">
                    裁切进度:
                  </a-col>
                  <a-col :span="4">
                    {{GetObjectvale(record,['clip','num'])}}/{{GetObjectvale(record,['clip','count'])}}
                  </a-col>
                  <a-col :span="16">
                    <a-progress :percent="parseInt((GetObjectvale(record,['clip','num'])-0)/(GetObjectvale(record,['clip','count'])-0)*100)" status="active"  />
                  </a-col>
                </div>
              </a-space>
            </a-descriptions-item>
            <a-descriptions-item label="转入解译任务"  :span="1">
              <a-space direction="vertical">
                <a-space>
                  <span>
                    转入解译任务-<span>{{GetObjectvale(record,['totask','type'])==1?"有":"无"}}</span>
                  </span>
                </a-space>
                 <a-space>
                  <span>
                   解译任务ID:  {{GetObjectvale(record,['totask','mongoid'])}}
                  </span>
                </a-space>
                <a-space>
                  <span>
                    转入状态:{{GetObjectvale(record,['totask','status'])}}
                  </span>
                  <span>
                    转入描述:{{GetObjectvale(record,['totask','msg'])}}
                  </span>
                </a-space>
              </a-space>
            </a-descriptions-item>
            <a-descriptions-item label="回调任务"  :span="1">
              <a-space direction="vertical">
                <a-space>
                  <span>
                    回调任务-<span>{{GetObjectvale(record,['action','type'])==1?"有":"无"}}</span>
                  </span>
                </a-space>
                 <a-space>
                  <span>
                    回调URL:  {{GetObjectvale(record,['action','url'])}}
                  </span>
                </a-space>
                <a-space>
                  <span>
                    上一次回调状态:{{GetObjectvale(record,['action','status'])}}
                  </span>
                </a-space>
                <a-space>
                  <span>
                    上一次回调描述:{{GetObjectvale(record,['action','msg'])}}
                  </span>
                </a-space>
                <a-space>
                  <span>
                    上一次回调时间:{{GetTime(GetObjectvale(record,['action','time']))}}
                  </span>
                </a-space>
                <a-space>
                  <span>
                    回调次数:{{GetObjectvale(record,['action','num'])}}
                  </span>
                </a-space>
              </a-space>
            </a-descriptions-item>
          </a-descriptions>
          </a-layout-content>
        </template>
        <template #bodyCell="{ text, record, index, column }">
          <template v-if="column.dataIndex === 'soft'">
            <span class="menu-name" v-show="record.soft.alibaba">alibaba</span>
            <span class="menu-name" v-show="record.soft.alibaba && record.soft.baidu">/</span>
            <span class="menu-name" v-show="record.soft.baidu">baidu</span> 
          </template>
          <template v-if="column.dataIndex === 'aistatus'">
            <span class="menu-name"><a-badge  :status="GetAIStatus(record,'alibaba')"/> {{GetAIStatusText(record,"alibaba")}}</span>
              /
            <span class="menu-name"><a-badge  :status="GetAIStatus(record,'baidu')"/> {{GetAIStatusText(record,"baidu")}}</span>
          </template>
          <template v-if="column.dataIndex === 'clip'">
            <span class="menu-name">{{record.clip.type-0==1?'是':'否'}}</span> 
          </template>
          <template v-if="column.dataIndex === 'clipstatus'">
            <span class="menu-name">{{record.clip.status}}</span> 
          </template>
          <template v-if="column.dataIndex === 'totask'">
            <span class="menu-name">{{record.totask.type-0==1?'是':'否'}}</span> 
          </template>
          <template v-if="column.dataIndex === 'totaskstatus'">
            <span class="menu-name">{{record.totask.status}}</span> 
          </template>
          <template v-if="column.dataIndex === 'action'">
            <span class="menu-name">{{Get_action_vale(record.action,'type')==1?'是':'否'}}</span> 
          </template>
          <template v-if="column.dataIndex === 'actionstatus'">
            <span class="menu-name">{{Get_action_vale(record.action,'status')}}</span> 
          </template>
          <template v-if="column.dataIndex === 'operation'">
            <span class="table-operation">
                <a-dropdown>
                  <a class="ant-dropdown-link" @click.prevent>操作<DownOutlined /></a>
                  <template #overlay>
                    <a-menu-item v-show="isaggregate==true">
                      <a href="javascript:;" @click="search_ai(record)">查询具体任务</a>
                    </a-menu-item>
                    <a-menu-item>
                        <a href="javascript:;" @click="swap_task(record)">转到任务</a>
                    </a-menu-item>
                    <a-menu-item>
                        <a href="javascript:;" @click="download_task(record)">下载任务</a>
                    </a-menu-item>
                    <a-menu-item>
                        <a href="javascript:;" @click="swap_to_task(record)">推送到</a>
                    </a-menu-item>
                    <a-menu-item>
                        <a href="javascript:;" @click="delete_task(record)">删除</a>
                    </a-menu-item>
                    <a-menu-item>
                        <a href="javascript:;" @click="merge_task_to(record)">合并到</a>
                    </a-menu-item>
                    </template>
                </a-dropdown>
            </span>
          </template> 
        </template>
      </a-table>
    </div>
    <a-drawer
      title="下载结果"
      placement="left"
      :closable="false"
      :visible="download_visible"
      @close="downloadClose"
      width="20%"
    >
    <a-row>
      <div class="props">
        <label>状态选择：</label>
        <a-select style="width: 260px" @change="StatusSelectChange" allowClear v-model="download.status" mode="multiple">
          <a-select-option :value="item.status" v-for="(item,index) in detail_status" :key="index" :disabled="item.disabled" v-show="index>=0">{{item.name}}</a-select-option>
        </a-select>
      </div>
    </a-row>
    <a-divider />
    <a-row>
      <div :class="['c-region']" style="margin: 10px 0 10px 0;" >
        <div class="c-r-select c-region__item c-region__item--city">
          <label for="" class="c-r-select__label">地级市/州/盟</label>
          <a-select v-model="active_level2" style="width: 120px" class="c-r-select__select"  @select="select2event" allowClear>
            <a-select-option :value="im2.properties.code"  v-for="(im2 ,index2 ) in level2_values" :key="index2">{{im2.properties.name}}</a-select-option>
          </a-select>
        </div>
        <div class="c-r-select c-region__item c-region__item--qu">
          <label for="" class="c-r-select__label">区/县/旗</label>
          <a-select  v-model="active_level3" style="width: 120px" class="c-r-select__select"    allowClear>
            <a-select-option :value="im3.properties.code"  v-for="(im3 ,index3 ) in level3_values"  :key="index3">{{im3.properties.name}}</a-select-option>
          </a-select>
        </div>
       </div>
    </a-row>
    <a-row>
      <a-button class="operation-a" type="link"  @click="True_DownTask()" style="width: 100%;">开始下载</a-button>
    </a-row>
    </a-drawer>
  </div>
</template>
<script>
export default {
  data() {
    return {
      taskid:'',//输入
      aiid:'',//输入
      status:'',//输入
      isaggregate:true,
      aggregate_table_data:[],
      aggregate_table_pagination:{
        size:'small',
        pageSize:15,
        total:0,
        showTotal:(total, range)=>{
          return `共 ${total} 个，当前${range[0]}-${range[1]}`
        },
      },
      aggregate_table_columns:[
        {
          title: '任务名',
          dataIndex: 'task_name',
          width:130,
          align:'center'
        },
        {
          title: '任务ID',
          dataIndex: 'taskid',
          width:200,
          align:'center'
        },
        {
          title: '用户',
          dataIndex: 'user',
          width:80,
          align:'center'
        },
        {
            title: '数量',
            dataIndex: 'count',
            width:80,
            align:'center'
        },
        {
          title: '操作',
          width:80,
          dataIndex: 'operation',
          align:'center'
        },
      ],
      aggregate_table_row_event: record => ({
        on: {
          dblclick: () => {
              this.search_ai(record);
          },
        },
      }),
      ai_table_data:[],
      ai_table_pagination:{
        size:'small',
        pageSize:10,
        total:0,
        showTotal:(total, range)=>{
          return `共 ${total} 个，当前${range[0]}-${range[1]}`
        },
      },
      ai_table_columns:[
        {
          title: '序号',
          dataIndex: 'keyvalue',
          width:20,
          align:'center'
        },
        {
          title: 'AI ID',
          dataIndex: 'aiid',
          width:90,
          align:'center'
        },
        {
          title: '软件',
          dataIndex: 'soft',
          width:60,
          align:'center'
        },
        {
          title: 'AI状态',
          dataIndex: 'aistatus',
          width:80,
          ellipsis:true,
          align:'center'
        },
        {
          title: '裁切',
          dataIndex: 'clip',
          width:20,
          ellipsis:true,
          align:'center'
        },
        {
          title: '裁切状态',
          dataIndex: 'clipstatus',
          width:40,
          ellipsis:true,
          align:'center'
        },
        {
          title: '转入任务',
          dataIndex: 'totask',
          width:40,
          ellipsis:true,
          align:'center'
        },
        {
          title: '转入状态',
          dataIndex: 'totaskstatus',
          width:40,
          ellipsis:true,
          align:'center'
        },
        {
          title: '回调任务',
          dataIndex: 'action',
          width:40,
          ellipsis:true,
          align:'center'
        },
        {
          title: '回调状态',
          dataIndex: 'actionstatus',
          width:40,
          ellipsis:true,
          align:'center'
        },

    
        {
          title: '操作',
          key: 'taskid',
          width:80,
          dataIndex: 'operation',
          align:'center'
        },
      ],
      ai_soft:undefined,
      ai_status:undefined,
      clip_type:undefined,
      clip_status:undefined,
      totask_type:undefined,
      totask_status:undefined,
      action_type:undefined,
      action_status:undefined,
      

      Interval_time: 3000,
      Interval_handlers:[],
      Interval_handler: null,




      download_visible:false,
      download:{
        taskid:"",
        status:[1],
      },
      level2_values:[],
      active_level2:"",
      level3_values:[],
      active_level3:"",
      
      
    }
  },
  beforeDestroy() {
    this.clearIntervals()
  },
  methods: {
    change_taskid(){
      this.search();
    },
    change_aiid(){
      this.search();
    },
    ai_soft_change(){
      this.search(1);
    },
    ai_status_change(){
      this.search(1);
    },
    clip_type_change(){
      this.search(1);
    },
    clip_status_change(){
      this.search(1);
    },
    totask_type_change(){
      this.search(1);
    },
    totask_status_change(){
      this.search(1);
    },
    action_type_change(){
      this.search(1);
    },
    action_status_change(){
      this.search(1);
    },
    click_and_search(){
      this.search();
    },
    search(pagenum=1){
      this.clearIntervals()
      this.aggregate_table_data=[]
      this.ai_table_data=[]
      let qs={
        pagesize:this.ai_table_pagination.pageSize,
        pagenum
      }
      {
        if(this.ai_soft){
          qs.ai_soft=this.ai_soft
        }
        if(this.ai_status){
          qs.ai_status=this.ai_status
        }
        if(this.clip_type){
          qs.clip_type=this.clip_type
        }
        if(this.clip_status){
          qs.clip_status=this.clip_status
        }
        if(this.totask_type){
          qs.totask_type=this.totask_type
        }
        if(this.totask_status){
          qs.totask_status=this.totask_status
        }
        if(this.action_type){
          qs.action_type=this.action_type
        }
        if(this.action_status){
          qs.action_status=this.action_status
        }
      }
      if(this.taskid !=""){
        qs.taskid=this.taskid
      }
      if(this.aiid !=""){
        qs.aiid=this.aiid
      }
      // this.$common_apis.axios_get("/search_ai_task?")
      global["vapp"].config.globalProperties.$axios_get("/change/search_ai_task?",qs).then( async (result) => {
        if(result && result.length>0){
          this.isaggregate=true;
          for (let index = 0; index < result.length; index++) {
            let _featrue = result[index];
            _featrue.key=index
            _featrue.keyvalue=index+1+(pagenum-1)*this.ai_table_pagination.pageSize
          }
          this.aggregate_table_data=result
        }
        else if(result && result.data  && result.page){
          this.isaggregate=false;
          let result_data=result.data
          for (let index = 0; index < result_data.length; index++) {
            let _featrue = result_data[index];
            _featrue.key=index
            _featrue.keyvalue=index+1+(pagenum-1)*this.ai_table_pagination.pageSize
          }
          this.ai_table_pagination.total=result.page.count
          this.ai_table_data=result_data
        }
      })
    },
    search_ai(record){
      this.taskid=record.taskid
      this.search(1)
    },
    ai_table_change_pagination(pagination){
      this.search(pagination.current)
    },
    search_aitask_clip_process(aiid){
      global["vapp"].config.globalProperties.$axios_get("/change/search_aitask_clip_process?",{
        aiid,
      }).then(  (result) => {
        let find_index=this.ai_table_data.findIndex((val)=>{
          return val.aiid==aiid
        })
        if(find_index>=0){
          this.ai_table_data[find_index].clip.num=result
        }
      })
    },
    clearIntervals(aiid){
      if(aiid){
        let index=this.Interval_handlers.findIndex((val)=>{
          return val.aiid==aiid
        })
        if(index>=0){
          clearInterval(this.Interval_handlers[index].Interval_handler);
          this.Interval_handlers.splice(index,1)
        }
      }
      else{
        for (let index = 0; index < this.Interval_handlers.length; index++) {
          let element = this.Interval_handlers[index];
          clearInterval(element.Interval_handler);
        }
        this.Interval_handlers=[]
      }
    },  
    ai_table_expand(expanded, record){
      if(expanded==false){
        this.clearIntervals(record.aiid);
      }
      else{
        let num=this.GetObjectvale(record,['clip','num'])-0
        let count=this.GetObjectvale(record,['clip','count'])-0
        if(count>num){
          this.search_task_Interval(record.aiid)
        }
      }
    },
    async search_task_Interval(aiid) {
      this.search_aitask_clip_process(aiid);
      let Interval_handler = setInterval(async () => {
        this.search_aitask_clip_process(aiid);
      }, this.Interval_time);
      this.Interval_handlers.push({
        aiid,
        Interval_handler,
      })
    },
    GetAIStatus(record,_ali_baidu){
      let aistatus=record?.soft?.[_ali_baidu]?.aistatus
      if(aistatus=="1"){
        return 'success'
      }
      else if(aistatus=="2"){
        return 'error'
      }
      else if(aistatus=="3"){
        return 'processing'
      }
      else{
        return 'default'
      }
    },
    GetAIStatusText(record,_ali_baidu){
      let ali_bai=record?.soft?.[_ali_baidu]
      if(ali_bai){
        let aimessage=ali_bai?.aimessage
        return aimessage?aimessage:""
      }
      else{
        return "无任务"
      }
    },
    Get_action_vale(_action,_value){
      if(_action){
        return _action[_value]
      }
      else{
        return _action
      }
    },
    Getsoftvale(record,_soft,_ali_baidu,_key){
      let ali_bai=record?.soft?.[_ali_baidu]
      if(ali_bai){
        return ali_bai[_key]
      }
      else{
        return undefined
      }
    },
    GetObjectvale(record,_route=['']){
      let val=record
      for (let index = 0; index < _route.length; index++) {
        let element = _route[index];
        val=val[element]
        if(!val){
          return val
        }
      }
      return val
    },





    Getclipstatus(record_clip){
      let _status=record_clip?.status
      if(_status){
        _status=_status.replace('waiting','default')
      }
      else{
        return 'default'
      }
    },
    GetStatus1(ai_app){
        if(ai_app && ai_app.finished=='1'){
            return 'success'
        }
        else if(ai_app && ai_app.finished=='0'){
            return 'processing'
        }
        else if(ai_app && ai_app.finished=='2'){
            return 'error'
        } else {
          return ''
        }
    },



    GetStatus2(ai_app){
        if(ai_app=='1'){
            return 'success'
        }
        else if(ai_app=='2'){
            return 'error'
        }
        else{
            return 'default'
        }
    },
    GetStatus2_text(ai_app){
        if(ai_app=='1'){
            return 'success'
        }
        else if(ai_app=='2'){
            return 'error'
        }
        else{
            return 'no'
        }
    },
    GetStatus3(ai_app){
        if(ai_app=='1'){
            return 'success'
        }
        else if(ai_app=='0'){
            return 'processing'
        }
        else if(ai_app=='2'){
            return 'error'
        }
        else{
            return 'default'
        }
    },
    GetStatus3_text(ai_app){
        if(ai_app=='1'){
            return 'success'
        }
        else if(ai_app=='0'){
            return 'processing'
        }
        else if(ai_app=='2'){
            return 'error'
        }
        else{
            return 'no'
        }
    },
    

    SelectChange(){
      this.search();
    },
    
    merge_tasks_show(){

    },
    swap_task(record){//转到任务

    },
    download_task(record){//下载任务

    },
    swap_to_task(record){//推送到

    },
    delete_task(record){//删除

    },
    merge_task_to(record)//合并到
    {

    },
    FenPei(taskid,can_fenpei=true){
      Bus.emit('task_manager_show',2);
      Bus.emit('task_manager_fenpei_taskid',taskid,can_fenpei);
    },
    StartTask(taskid){
      this.$axios.post("/update_task?",{
        taskid,
        status:0,
        stime:new Date().getTime()
      })
      .then(res => {
        let BackData=res.data
        if (BackData.status == true) {
          this.$message.success(`开始任务${taskid}成功`)
          this.search();
        }
        else{
          this.$message.error(`StartTask from server error.${BackData.message}`)
        }
      });
    },
    EndTask(taskid){
      this.$axios.post("/update_task?",{
        taskid,
        status:1,
        etime:new Date().getTime()
      })
      .then(res => {
        let BackData=res.data
        if (BackData.status == true) {
          this.$message.success(`结束任务${taskid}成功`)
          this.search();
        }
        else{
          this.$message.error(`EndTask from server error.${BackData.message}`)
        }
      });
    },
    DeleteTask(taskid){
      this.$axios.post("/delete_task?", {
        taskid
      })
      .then(res => {
        let BackData=res.data
        if (BackData.status == true) {
          this.$message.success(`删除任务${taskid}成功`)
          this.search();
        }
        else{
          this.$message.error(`DeleteTask from server error.${BackData.message}`)
        }
      });
    },
    DownTask(taskid){

      this.download_visible=true;
      this.download.taskid=taskid
    },
    True_DownTask(){
      let qs={
        taskid:this.download.taskid
      }
      if(this.active_level3){
        qs.xzqhcode=this.active_level3
      }
      else if(this.active_level2){
        qs.xzqhcode=this.active_level2
      }
       if(this.download.status.length>0){
        let code=this.download.status.join(',')
        qs.code=code
      }
      this.$axios.get("/download?", { params: qs})
      .then(res => {
        let BackData=res.data
        if (BackData.status == true) {
          let _href=`${window.Glod.baseurl}download_path?taskid=${this.download.taskid}`
          window.open(_href, '_blank');
        }
        else{
          this.$message.error(`download from server error.${BackData.message}`)
        }
      });
    },
    downloadClose(){
      this.download_visible=false;
    },
    changeEvent(pagination){
      this.search(pagination.current)
    },
    async search_process(){
      let _finds=this.detail_status.filter((_detail_status)=>{
        return _detail_status.status>=0
      })
      let _statusNeed=[]
      _finds.forEach((_find)=>{
        _statusNeed.push(_find.status)
      })
      for(let i=0;i <this.table_data.length;i++){
        let qs={
          pagesize:1,
          pagenum:1,
          mergeid:this.table_data[i].mergeid,
          status:_statusNeed.join(',')//"0,1,2,3,4,5"
        }
        let res=await this.$axios.get("/search?",{ params: qs})
        let BackData=res.data
        if (BackData.status == true) {
          this.table_data[i].process=parseInt(BackData.result.page.count/BackData.result.page.countAll*100)
        }
        else{
            this.table_data[i].process=0
        }
      }
      this.$forceUpdate()
    },
    dblclick(record){
      this.FenPei(record.taskid,false)
    },
    Get_xzqh_level_2(){
      this.$axios.get("http://talatan.com:29111/geoserver/cite/wfs?",{params:{
        service:'WFS',
        version:'1.1.0',
        request:'GetFeature',
        TYPENAME:'cite:xzqh',
        outputFormat:'application/json',
        SRSNAME:'EPSG:3857',
        PROPERTYNAME:'name,code,precode,level',//geom
        FILTER:`<Filter><PropertyIsEqualTo><PropertyName>level</PropertyName><Literal>2</Literal></PropertyIsEqualTo></Filter>`,
      }})
      .then(res => {
        let BackData=res.data
        this.level2_values=BackData.features;
      });
    },
    select2event(value, option){
      this.level3_values=[]
      this.active_level3="";
      this.$axios.get("http://talatan.com:29111/geoserver/cite/wfs?",{params:{
        service:'WFS',
        version:'1.1.0',
        request:'GetFeature',
        TYPENAME:'cite:xzqh',
        outputFormat:'application/json',
        SRSNAME:'EPSG:3857',
        PROPERTYNAME:'name,code,precode,level',//geom
        FILTER:`<Filter><PropertyIsEqualTo><PropertyName>precode</PropertyName><Literal>${value}</Literal></PropertyIsEqualTo></Filter>`,
      }})
      .then(res => {
        let BackData=res.data
        this.level3_values=BackData.features;
      });
      console.log(value, option)
    },

  },
}
</script>